#include "StdAfx.h"
#include "SubStructure.h"
#include "GameBase.h"
#include "randomseed.h"
#include "jsonreader.h"
#include "Item.h"
#include "ItemFactory.h"

ItemFactory::ItemFactory()
{
	reader= jsonreader::Instance();
	randseed = randomseed::Instance();
	if(D3DXCreateTextureFromFileEx(pd3dDevice, _T("etama2.png"), 256, 256, 1, NULL,
		D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0x00000000, NULL, NULL, &itemTexture))
		MessageBox(NULL, _T("etama2.png is not loaded!!!"), _T("ERROR"), MB_OK);
}

ItemFactory* ItemFactory::Instance()
{
	if(_p_this == NULL)
	{
		_p_this = new ItemFactory();
	}
	return _p_this;
}

ItemList ItemFactory::makeItem(Event_struct* ev)
{
	ItemList tList;
	Item temp;
	RECT tR;
	SetRect(&tR, ev->kind * 16, 64, (ev->kind + 1) * 16, 80);
	temp.Setrect(tR);
	temp.Set_kind(ev->kind);
	temp.SetTexture(itemTexture);
	temp.Init();
	for(DWORD i = 0; i < ev->sub1; ++i)
	{
		Item* tI = new Item(temp);
		tI->SetPos(ev->makePos + D3DXVECTOR2(randseed->getrandAsFLOAT(i * 11 + ev->kind) * 60.0f - 30.0f, randseed->getrandAsFLOAT(999 - ((i * 11) + ev->kind)) * 60.0f - 30.0f));
		tList.push_back(tI);
	}
	return tList;
}